//
//  OrderExtFooterView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/18.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "OrderExtFooterView.h"

@interface OrderExtFooterView()<UITextFieldDelegate,UITextViewDelegate>
@end

@implementation OrderExtFooterView

{
    NSMutableArray*sumPrices;
    UILabel *label;
    UIImageView*im;
    UIView*footerView;
}
@synthesize mDelegate;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIView*myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
        myToolBar.backgroundColor=jianpancolor;
        UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
        [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:tubtnDone];
        UIButton*btnDone=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
        [btnDone setTitle:@"确定" forState:UIControlStateNormal];
        [btnDone setTitleColor:jianpancolor1 forState:UIControlStateNormal];
        btnDone .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
        [btnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:btnDone];
        myToolBar.alpha=alp;
        UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
        [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
        [myToolBar addSubview:dabtn];
        
        UIScrollView*MYmainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
        [MYmainScroll setBackgroundColor: zuiqianhuiColor];
        MYmainScroll.delegate = self;
        MYmainScroll.userInteractionEnabled = YES;
        MYmainScroll.scrollEnabled = YES;
        MYmainScroll.showsVerticalScrollIndicator = FALSE;
        MYmainScroll.showsHorizontalScrollIndicator = FALSE;
        [self addSubview:MYmainScroll];
        
        
        footerView=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 200)];
        footerView.backgroundColor=[UIColor whiteColor];
        [MYmainScroll addSubview:footerView];
        
        UILabel *lineLabel12=[[UILabel alloc] initWithFrame:CGRectMake(15, 90-0.35, ScreenWidth-30, 0.35)];
        lineLabel12.backgroundColor=qianhuiColor;
        [footerView addSubview:lineLabel12];
        UILabel *lineLabel112=[[UILabel alloc] initWithFrame:CGRectMake(15, 135-0.35, ScreenWidth-30, 0.35)];
        lineLabel112.backgroundColor=qianhuiColor;
        [footerView addSubview:lineLabel112];
        UILabel *lineLabel13=[[UILabel alloc] initWithFrame:CGRectMake(0, 200-0.35, ScreenWidth, 0.35)];
        lineLabel13.backgroundColor=qianhuiColor;
        [footerView addSubview:lineLabel13];
        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-30, 0.5)];
        _xianview.image=[UIImage imageNamed:@"hengxian"];
        [footerView addSubview:_xianview];
        UIImageView *_xianview1 = [[UIImageView alloc]initWithFrame:CGRectMake(15,45, ScreenWidth-30, 0.5)];
        _xianview1.image=[UIImage imageNamed:@"hengxian"];
        [footerView addSubview:_xianview1];
        _discountTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-100,45)];
        _discountTextFied.borderStyle = UITextBorderStyleNone;
        _discountTextFied.keyboardType = UIKeyboardTypeDecimalPad;
        _discountTextFied.font = [UIFont systemFontOfSize: contenfot];
        _discountTextFied.textColor=[UIColor blackColor];
        _discountTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
        _discountTextFied.tag=1;
        _discountTextFied.placeholder = @"请输入整单折扣金额"; //默认显示的字
        _discountTextFied.delegate = self;
        [_discountTextFied setUserInteractionEnabled:YES];
        _discountTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
        [footerView addSubview:_discountTextFied];
        _discountTextFied.inputAccessoryView = myToolBar;
        
        
        _discountRateSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-100,  0, 60,50)];
        _discountRateSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
        _discountRateSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_discountRateSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [footerView addSubview:_discountRateSatBtn];
        UIButton*jiantouBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,110-90,46/3, 25/3)];
        [jiantouBtn setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
        [footerView addSubview:jiantouBtn];
   

        
        
        
        _discountAmountLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 45, ScreenWidth-40, 45)];
//       _discountAmountLabel.text=[NSString stringWithFormat:@"优惠后金额¥%@" ,formattedNumberString];
        _discountAmountLabel.textColor=[UIColor blackColor];
        _discountAmountLabel.textAlignment = NSTextAlignmentRight;
        [footerView addSubview:_discountAmountLabel];
        
        
        
        UILabel*shifou=[[UILabel alloc]initWithFrame:CGRectMake(15, 87.5, 80, 50)];
        shifou.text=@"是否定金";
        shifou.textColor=shenhuiColor;
        shifou.font=[UIFont systemFontOfSize:14];
        [footerView addSubview:shifou];
        
        
        _switchs = [[UISwitch alloc] initWithFrame:CGRectMake(ScreenWidth-75, 97.5, 55, ScreenHeight*15/1334)];
        _switchs.onTintColor=luseColor;
        _switchs.on = NO;
        [footerView addSubview:_switchs];
    
        _depositTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15,140, ScreenWidth-100,50)];
        _depositTextFied.borderStyle = UITextBorderStyleNone;
        _depositTextFied.keyboardType = UIKeyboardTypeDecimalPad;
        _depositTextFied.font = [UIFont systemFontOfSize: contenfot];
        _depositTextFied.textColor=[UIColor blackColor];
        _depositTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
        _depositTextFied.tag=2;
        _depositTextFied.placeholder = @"请输入定金金额"; //默认显示的字
        _depositTextFied.delegate = self;
        [_depositTextFied setUserInteractionEnabled:NO];
        _depositTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
        [footerView addSubview:_depositTextFied];
        _depositTextFied.inputAccessoryView = myToolBar;
        
        
        _earnestRateSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-100, 225-85, 60,50)];
        _earnestRateSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
        _earnestRateSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_earnestRateSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [footerView addSubview:_earnestRateSatBtn];
        UIButton*jiantouBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,245-86,46/3, 25/3)];
        [jiantouBtn1 setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
        [footerView addSubview:jiantouBtn1];

        //加载配送界面
        
        UIView*view5=[[UIView alloc]initWithFrame:CGRectMake(0, footerView.bottom+10, ScreenWidth, 50)];
        view5.backgroundColor=[UIColor whiteColor];
        view5.layer.borderWidth = 0.35;
        view5.layer.borderColor = qianhuiColor.CGColor;
        [MYmainScroll addSubview:view5];
        UILabel*fangshi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 50)];
        fangshi.text=@"配送方式";
        fangshi.textColor=shenhuiColor;
        fangshi.font=[UIFont systemFontOfSize:14];
        [view5 addSubview:fangshi];
        
        _distributionSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-20,  0, ScreenWidth/2-20,50)];
        _distributionSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
        _distributionSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [_distributionSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [view5 addSubview:_distributionSatBtn];
        UIButton* distributionSatBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,20,46/3, 25/3)];
        [distributionSatBtn1 setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
        [view5 addSubview:distributionSatBtn1];

        UIView*view6=[[UIView alloc]initWithFrame:CGRectMake(0, view5.bottom+10, ScreenWidth, 120)];
        view6.backgroundColor=[UIColor whiteColor];
        view6.layer.borderWidth = 0.35;
        view6.layer.borderColor = qianhuiColor.CGColor;
        [MYmainScroll addSubview:view6];
        
        _noteTextView=[[UITextView alloc]init];
        _noteTextView.frame=CGRectMake(20, 10, ScreenWidth-40, 90);
        _noteTextView.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
        _noteTextView.scrollEnabled = YES;//是否可以拖动
        _noteTextView.delegate=self;
        _noteTextView.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
        _noteTextView.layer.borderWidth =0.0;
        CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
        [_noteTextView.layer setBorderColor:tureBTncolorref111];//边框颜色
        _noteTextView.layer.cornerRadius =0;
        [view6 addSubview:_noteTextView];
        im=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5,18, 16)];
        im.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [_noteTextView addSubview:im];
        label=[[UILabel alloc]init];
        label.frame =CGRectMake(23, 7, ScreenWidth-60, 14);
        label.text = @"备注";
        label.textColor=zuiqianhuiColor;
        label.numberOfLines=0;
        label.font=[UIFont systemFontOfSize:14];
        label.enabled = NO;//lable必须设置为不可用
        label.backgroundColor = [UIColor clearColor];
        [_noteTextView addSubview:label];
        _noteTextView.inputAccessoryView = myToolBar;

        
    }
    return self;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
     [mDelegate textFieldEditing:[NSString stringWithFormat:@"%ld", textField.tag]];
    
    
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [mDelegate textViewEditing:@""];
    return self;
}


-(void)textViewDidChange:(UITextView *)textView
{
  
    
    if (textView.text.length == 0) {
        [im removeFromSuperview];
        
        im=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 18, 16)];
        im.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [_noteTextView addSubview:im];
        label.text = @"备注";
        
    }else{
        [im removeFromSuperview];
        label.text = @"";
    }
}


-(void)OnTapDone{
    [mDelegate key:@""];

}



@end
